<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0"
	xmlns:exist="http://exist.sourceforge.net/NS/exist">

	<xsl:param name="exist-url">http://localhost:8080/orbeon/exist/rest/db/ead/</xsl:param>
	<xsl:param name="eaditor-url">http://localhost:8080/orbeon/ead/</xsl:param>

	<xsl:template match="/">
		<html>
			<head>
				<title>EADitor File Manager</title>
				<link rel="stylesheet" href="style.css"/>
				<script type="text/javascript" src="javascript/jquery-1.3.2.min.js"/>
				<script type="text/javascript" src="javascript/get_components.js"/>
			</head>
			<body>
				<div id="wrap">
					<h1>EADitor File Manager</h1>
					<p>
						<a href="{$eaditor-url}" target="_blank">Create New Guide</a>
					</p>
					<xsl:if test="//exist:resource">
						<h2>List of Guides</h2>
					</xsl:if>
					<xsl:apply-templates select="//exist:resource"/>
				</div>
			</body>
		</html>
	</xsl:template>

	<xsl:template match="exist:resource">
		<xsl:variable name="file" select="concat($exist-url, @name)"/>
		<xsl:variable name="class">
			<xsl:choose>
				<xsl:when test="position() mod 2 = 0">even-row</xsl:when>
				<xsl:otherwise>odd-row</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>

		<div class="{$class}">
			<h3>
				<a href="{$eaditor-url}?guide={document($file)/ead/@id}" target="_blank"
						><xsl:value-of select="document($file)//titlestmt/titleproper"/>
						(<xsl:value-of select="document($file)//eadid"/>)</a>
				<a href="get_components/{document($file)/ead/@id}" class="expand"
					id="{document($file)/ead/@id}_link">expand</a>
			</h3>
			<div class="contents" id="{document($file)/ead/@id}_container" style="display:none"/>
		</div>
	</xsl:template>

</xsl:stylesheet>
